package C013;

public class MyCircularQueue {

    public static void main(String[] args) {
        MyCircularQueue queue = new MyCircularQueue(3);
        System.out.println(queue.enQueue(1));
    }
    int[] arr;
    int l, r, size, limit;

    public MyCircularQueue(int k) {
        arr = new int[limit];
        this.limit = k;
    }
    
    public boolean enQueue(int value) {
        if(isFull()) {
            return false;
        }
        arr[r++] = value;
        r = r == limit ? 0 : r;
        size++;
        return true;
    }
    
    public boolean deQueue() {
        if(isEmpty()) {
            return false;
        }
        int ele = arr[l ++];
        l = l == limit ? 0 : l;
        size --;
        return true;
    }
    
    public int Front() {
        if(isEmpty()) {
            return -1;
        }
        return arr[l];
    }
    
    public int Rear() {
        if (isEmpty()) {
            return -1;
        }
        return arr[r - 1 == -1 ? limit - 1 : r - 1];
    }

    public boolean isEmpty() {
        return size == 0;
    }

    public boolean isFull() {
        return size == limit;
    }
}

/**
 * Your MyCircularQueue object will be instantiated and called as such:
 * MyCircularQueue obj = new MyCircularQueue(k);
 * boolean param_1 = obj.enQueue(value);
 * boolean param_2 = obj.deQueue();
 * int param_3 = obj.Front();
 * int param_4 = obj.Rear();
 * boolean param_5 = obj.isEmpty();
 * boolean param_6 = obj.isFull();
 */